package com.hrsoft.edi.stub.request;

import com.qimen.api.QimenRequest;
import com.qimen.api.response.TransferorderCreateResponse;
import com.taobao.api.ApiRuleException;
import com.taobao.api.internal.mapping.ApiField;
import com.taobao.api.internal.mapping.ApiListField;
import com.taobao.api.internal.util.RequestCheckUtils;

import java.util.List;

/**
 * TOP API: taobao.qimen.entryorder.create request
 *
 * @author top auto create
 * @since 1.0, 2018.07.26
 */
public class TransferorderCreateRequest extends QimenRequest<TransferorderCreateResponse> {

    /**
     * 调拨单信息
     */
    private TransferOrder transferOrder;

    /**
     * 调拨单详情
     */
    @ApiListField("transferItems")
    @ApiField("transferItem")
    private List<TransferItem> transferItems;

    public TransferOrder getTransferOrder() {
        return transferOrder;
    }

    public void setTransferOrder(TransferOrder transferOrder) {
        this.transferOrder = transferOrder;
    }

    public List<TransferItem> getTransferItems() {
        return transferItems;
    }

    public void setTransferItems(List<TransferItem> transferItems) {
        this.transferItems = transferItems;
    }

    public String getApiMethodName() {
        return "transferorder.create";
    }

    public Class<TransferorderCreateResponse> getResponseClass() {
        return TransferorderCreateResponse.class;
    }

    public void check() throws ApiRuleException {
        RequestCheckUtils.checkNotEmpty(transferOrder.getOwnerCode(), "ownerCode");
        RequestCheckUtils.checkNotEmpty(transferOrder.getErpOrderCode(), "erpOrderCode");
        RequestCheckUtils.checkNotEmpty(transferOrder.getFromStoreCode(), "fromStoreCode");
        RequestCheckUtils.checkNotEmpty(transferOrder.getToStoreCode(), "toStoreCode");

        if (null == transferItems || transferItems.size() == 0) {
            throw new ApiRuleException(RequestCheckUtils.ERROR_CODE_ARGUMENTS_MISSING, "client-error:Missing required arguments:transferItems");
        }
        for (int j = 0; j < transferItems.size(); j++) {
            RequestCheckUtils.checkNotEmpty(transferItems.get(j).getScItemCode(), "transferItem.scItemCode" + " index:" + j);
            RequestCheckUtils.checkNotEmpty(transferItems.get(j).getCount(), "transferItem.count" + " index:" + j);
            RequestCheckUtils.checkNotEmpty(transferItems.get(j).getInventoryType(), "transferItem.inventoryType" + " index:" + j);
        }
    }

    /**
     * 调拨单信息
     *
     * @author top auto create
     * @since 1.0, null
     */

    public static class TransferOrder {

        /**
         * 货主编码
         */
        @ApiField("ownerCode")
        private String ownerCode;

        /**
         * 外部 ERP
         */
        @ApiField("erpOrderCode")
        private String erpOrderCode;

        /**
         * 出库仓编码
         */
        @ApiField("fromStoreCode")
        private String fromStoreCode;

        /**
         * 入库仓编码
         */
        @ApiField("toStoreCode")
        private String toStoreCode;

        /**
         * 期望调拨开始时间
         */
        @ApiField("expectStartTime")
        private String expectStartTime;

        public String getOwnerCode() {
            return ownerCode;
        }

        public void setOwnerCode(String ownerCode) {
            this.ownerCode = ownerCode;
        }

        public String getErpOrderCode() {
            return erpOrderCode;
        }

        public void setErpOrderCode(String erpOrderCode) {
            this.erpOrderCode = erpOrderCode;
        }

        public String getFromStoreCode() {
            return fromStoreCode;
        }

        public void setFromStoreCode(String fromStoreCode) {
            this.fromStoreCode = fromStoreCode;
        }

        public String getToStoreCode() {
            return toStoreCode;
        }

        public void setToStoreCode(String toStoreCode) {
            this.toStoreCode = toStoreCode;
        }

        public String getExpectStartTime() {
            return expectStartTime;
        }

        public void setExpectStartTime(String expectStartTime) {
            this.expectStartTime = expectStartTime;
        }
    }

    /**
     * 调拨单详情
     *
     * @author top auto create
     * @since 1.0, null
     */

    public static class TransferItem {

        /**
         * 货品编码
         */
        @ApiField("scItemCode")
        private String scItemCode;

        /**
         * 数量
         */
        @ApiField("count")
        private String count;

        /**
         * 库存类型(1:可销售库存.101:残次)
         */
        @ApiField("inventoryType")
        private Long inventoryType;

        public String getScItemCode() {
            return scItemCode;
        }

        public void setScItemCode(String scItemCode) {
            this.scItemCode = scItemCode;
        }

        public String getCount() {
            return count;
        }

        public void setCount(String count) {
            this.count = count;
        }

        public Long getInventoryType() {
            return inventoryType;
        }

        public void setInventoryType(Long inventoryType) {
            this.inventoryType = inventoryType;
        }
    }
}